package ar.edu.uba.fi.jmit.aspecter.testUtils;

import java.util.Map;

import org.apache.log4j.Logger;

import ar.edu.uba.fi.jmit.aspecter.core.CoreUtils;
import ar.edu.uba.fi.jmit.aspecter.core.WeavingInstrumentorImpl;
import ar.edu.uba.fi.jmit.aspecter.core.WeavingInstrumentorPlugin;
import ar.edu.uba.fi.jmit.aspecter.core.exception.AspecterException;
import ar.edu.uba.fi.jmit.aspecter.core.injector.simple.SimpleMethodInjector;

public class WeavingInstrumentorPluginTestImpl4 extends WeavingInstrumentorImpl implements WeavingInstrumentorPlugin {

private Map<String, String> properties;
	
	private String priority;

	@Override
	public void configure(Map<String, String> configurationProperties) throws AspecterException {
		this.properties = configurationProperties;
		String className = configurationProperties.get("methodToIntercept.method.class");
		String methodName = configurationProperties.get("methodToIntercept.method.name");
		String returnType = configurationProperties.get("methodToIntercept.method.return");
		SimpleMethodInjector injector = null;
		try {
			injector = new SimpleMethodInjector(methodName, CoreUtils.getClass(returnType));
		} catch (ClassNotFoundException e) {
			Logger.getLogger(this.getClass()).error("Could not configure plugin.", e);
			throw new AspecterException("Could not configure plugin.", e);
		}
		injector.setBeforeCode("throw new java.lang.RuntimeException(\"injected with plugin\");");
		injector.setMustInject(true);
		this.addInjector(className, injector);
	}

	@Override
	public void setPriority(String priority) {
		this.priority = priority;
	}

	public Map<String, String> getProperties() {
		return properties;
	}

	public void setProperties(Map<String, String> properties) {
		this.properties = properties;
	}

	public String getPriority() {
		return priority;
	}
}
